<!-- 验证插件 -->
<script src="/static/plugins/jquery-validation/jquery.validate.min.js"></script>
<script src="/static/plugins/jquery-validation/localization/messages_zh.min.js"></script>
<!-- 针对当前主题进行简单封装，精简代码 -->
<script src="/static/sdtheme/scripts/sdvalidate.js"></script>

<script>
    var index = parent.layer.getFrameIndex(window.name);

    $(function () {
        pageInit()
    });

    function pageInit() {
       $('#IfPatriarch').selectpicker('val', '{{.m.IfPatriarch}}');
       $('#IfTeacher').selectpicker('val', '{{.m.IfTeacher}}');
       $('#IfAdmin').selectpicker('val', '{{.m.IfAdmin}}');
       validateInfo();
    }

    function validateInfo() {
        var $thisForm = $('#thisForm');
        $thisForm.sdvalidate({
            rules: {
                Name: {
                    required: true
                }
            },
            submitHandler: function (form) {
                var url = '{{urlfor "NotificationCategoryController.Edit"}}';
                var params = $thisForm.serialize();
                $.sdpost(url, params, function (res) {
                    if (res.code === 0) {
                        parent.layer.msg(res.msg);
                        parent.refresh();
                        parent.layer.close(index);
                    } else {
                        parent.layer.alert(res.msg, {icon: 2, title: '失败'})
                    }
                });
                return false
            }
        });
    }

    function FormSubmit() {
        $('#thisForm').submit()
    }
</script>